<?php

class Defaults extends CI_Model{
    function __construct(){
        parent::__construct();
    }
    
    function get(){
        $result = $this->db->get("defaults");
        return $result->row();
    }
    
    function getTimes(){
        $this->db->order_by('available_time_time','asc');
        return $this->db->get('available_times');
    }
    
    function ordersAllowed(){
        $result = $this->db->get("defaults");
        $row = $result->row();
        return $row->default_orders;
    }
    
    function setDefaults($serve_time_id,$cutoff_time_id,
                    $mon,$tue,$wed,$thu,$fri,$sat,$sun, $active){
        $this->db->trans_start();
        
        $this->db->select('available_time_time');
        $this->db->where('available_time_id',$serve_time_id);
        $serve_time = $this->db->get('available_times')->row()->available_time_time;
        
        
        $this->db->select('available_time_time');
        $this->db->where('available_time_id',$cutoff_time_id);
        $cutoff_time = $this->db->get('available_times')->row()->available_time_time;
        
        $data["default_cutoff"] = $cutoff_time;
        $data["default_servetime"] = $serve_time;
        $data["default_monday"] = $mon;
        $data["default_tuesday"] = $tue;
        $data["default_wednesday"] = $wed;
        $data["default_thursday"] = $thu;
        $data["default_friday"] = $fri;
        $data["default_saturday"] = $sat;
        $data["default_sunday"] = $sun;
        $data["default_orders"] = $active;
        
        $this->db->update("defaults",$data);
        
        
        $this->db->trans_complete();
        return $this->db->trans_status();
    }
    
    function getFutureCount(){
        //STUB
        return 7;
    }
}

